package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.SecurityUtils;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.ElderDeviceInfo;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.BindFamilyMemberRequestDto;
import com.zzyl.nursing.dto.ElderFamilyResponseDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.job.vo.FamilyElderRelation;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import okhttp3.internal.Internal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/member/user")
@Api(tags =  "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

//    @PostMapping("/login")
//    @ApiOperation("小程序登录")
//    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
//        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
//        return success(loginVo);
//    }
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto){
        LoginVo loginVO = familyMemberService.login(userLoginRequestDto);
        return success(loginVO);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult bindingpeople(@RequestBody BindFamilyMemberRequestDto bindFamilyMemberRequestDto){
        familyMemberService.bindingpeople(bindFamilyMemberRequestDto);
        return success();
    }


    @GetMapping("my")
    @ApiOperation("查看家人列表")
    public R<List<FamilyElderRelation>> getFamilymy(){
        List<FamilyElderRelation> getfamulmy = familyMemberService.getfamulmy();
        return R.ok(getfamulmy);
    }

    @GetMapping("list-by-page")
    @ApiOperation("查看已绑定家人列表(分页查询)")
    public TableDataInfo<List<ElderDeviceInfo>> list(){
        startPage();
        List<ElderDeviceInfo> list = familyMemberService.listadd();
        return getDataTable(list);
    }
}